/**
 * 用户权限验证
 * @param options
 * @param app
 * @returns {sessionRedis}
 */
module.exports = () => {
    return async function Token(ctx, next) {

        // ctx.session.token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3ZCIsImV4cCI6MTUyMDQ2MDUyMCwiaWF0IjoxNTIwNDAwNTIwLCJ0b2tlbiI6IjIyN2RjN2MwNWUwNTQ2NDliY2UyMGQ3ZDA0MDQwZjU2In0.p1RZCJnWbwEKzOcnx41wZJHaDxbz2d1nafmMPXbnDR8';
        ctx.app.logger.info(ctx.url);

        const token = ctx.session.token;
        if (!token) {
            let data = await ctx.service.auth.get();
            ctx.app.logger.info(data);
            if (200 == data.code){
                let authorization = data.data.authorization;
                ctx.session.token = authorization;
            }
        }

        ctx.app.logger.info(`token:${ctx.session.token}`);

        await next();
    };
};
